﻿using Nop.Core.Domain.Customers;
using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nop.Data.Mapping.Customers
{
	public class CustomerRoleMappingMap : EntityTypeConfiguration<CustomerRoleMapping>
	{
		public CustomerRoleMappingMap()
		{
			this.ToTable("Customer_CustomerRole_Mapping");
			this.HasKey(crm => new { crm.CustomerId, crm.CustomerRoleId });
			this.Property( crm => crm.CustomerId).HasColumnName("Customer_Id");
			this.Property( crm => crm.CustomerRoleId).HasColumnName("CustomerRole_Id");
			this.Property( crm => crm.StartDate).IsOptional();
			this.Property( crm => crm.EndDate).IsOptional();

			this.HasRequired(crm=>crm.Customer)
				.WithMany(c=>c.CustomerRoleMappings)
				.HasForeignKey(crm=>crm.CustomerId);

			this.HasRequired(crm=>crm.CustomerRole)
				.WithMany(cr=>cr.CustomerRoleMappings)
				.HasForeignKey(crm=>crm.CustomerRoleId);
			this.Ignore(cr => cr.Id);
		}
	}
}
